<template>
	<view class="xilu">
		<hx-navbar :config="config">
			<block slot="center">
				<view class=""></view>
			</block>
		</hx-navbar>
		<view class="page-foot">
			<Footer :identity="3" :footState="2"></Footer>
		</view>
		<!-- <view class="back" @click="toBack"> <image src="/static/返回.png" mode="" class="back-img"></image>  </view> -->
		<view class="container">
			<image v-if="web_url" :src="web_url+'/uniapp_image/xilu_mine_bg.png'" mode="aspectFill" class="xilu_mine_bg"></image>
			<template v-if="login_status">
				
				<view class="pr z2">
					<view class="pt20 pb40 plr40 flex-box">
						<image :src="info.xilufitness_urls.shop_logo_image || '../../static/images/avatar.png' "
							mode="aspectFill" class="xilu_head_img">
						</image>
						<view class="flex-grow-1 pl30">
							<view class="fs40 colf fw500 lh56">{{info.shop_name || ''}}</view>
							<view class="flex-box mt20" v-if="info.group_image">
								<image :src="info.group_image" mode="widthFix" class="ico160"></image>
							</view>
						</view>
					</view>
					
					<view class="flex-box">
						
						<view class="flex-grow-1 tc">
							<view class="col2 fs42 fw500 lh60">{{info.accountInfo.wait_course_money || 0}}</view>
							<view class="mt10 fs28 colf">待上课佣金</view>
						</view>
					</view>
					
					
					
					<view class="plr25 ptb40">
					<view class="xilu_vip_nav" @click="to_shop_member_card(rechargeInfo.id || 0)">
					  <image v-if="web_url" :src="web_url+'/uniapp_image/xilu_vip_card.png'" mode="aspectFill"
					    class="xilu_vip_nav_bg">
					  </image>
					  <view class="xilu_vip_nav_view plr30 flex-box">
					    <view class="flex-grow-1">
					      <view class="fs42 colf lh56 fwb">门店套餐</view>
					      <view class="fs20 fw500 colf lh28 ls10">SHOP MEMBERSHIP CARD</view>
					      <!-- 套餐状态 -->
					      <view class="fs30 lh42 mt25" :class="['vip-status', getVipStatusClass(info.expire)]">
					        <text>
					          {{ getVipStatusText(info.expire) }}
					        </text>
					      </view>
					      <!-- 有效期 -->
					      <view class="fs26 colf lh36 mt8"  v-if="info.expire == 1">
					        有效期：
					        <text v-if="info.expire == 1">
					          {{ info.starttime }} ~ {{ info.endtime }}
					        </text>
					      </view>
					    </view>
					    <view class="xilu_go">
					      {{ info.expire == 1 ? '续费' : '开通' }}
					    </view>
						
					  </view>
					</view>
						
						<view class="xilu_vip_nav">
							<image v-if="web_url" :src="web_url+'/uniapp_image/xilu_profile_card.png'" mode="aspectFill"
								class="xilu_vip_nav_bg">
							</image>
							<view class="xilu_vip_nav_view plr30 flex-box">
								<view class="flex-grow-1" @tap="redirect_url('../my_shop_income/my_shop_income')">
									<view class="fs28 colf lh28">可提现金额（元）</view>
									<view class="fs30 mt20 colf lh50">¥<text
											class="fs50">{{info.accountInfo.account || 0.00}}</text></view>
									<view class="fs28 colf lh28 mt40">全部金额（元）</view>
									<view class="fs30 colf lh34 mt15">¥<text
											class="fs34">{{info.accountInfo.total_account || 0.00}}</text></view>
								</view>
								<view @tap="redirect_url('../shop_payouts/shop_payouts')" class="xilu_go">提现</view>
							</view>
						</view>
						<view class="xilu_box">
							<view class="fs36 fw500 col3 lh36">其他功能</view>
							<view>
								<button @tap="redirect_url('../shop_stats/shop_stats')" class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_footer2_uc.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>门店中心</view>
								</button>
								<button @tap="redirect_url('../shop_orders/shop_orders')" class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_footer2_uc.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>订单列表</view>
								</button>
								<button @tap="redirect_url('../shop_member_order/shop_member_order')" class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_footer2_uc.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>套餐记录</view>
								</button>
								<button @click="returnindex('../mine/mine')"
									class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_close.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>退出</view>
								</button>
								
							</view>
						</view>
					</view>
				</view>

			</template>

			<template v-else>

				<view class="pr z2" @tap="doLogin()">
					<view class="pt20 pb40 plr40 flex-box">
						<image src="@/static/images/avatar.png" mode="aspectFill" class="xilu_head_img">
						</image>
						<view class="flex-grow-1 pl30">
							<view class="fs40 colf fw500 lh56">点击登录</view>
							<view class="flex-box mt20">
								<image src="@/static/images/xilu_label_low.png" mode="widthFix" class="ico160"></image>
							</view>
						</view>
					</view>
					
					<view class="plr25 ptb40">
						<view class="xilu_vip_nav">
							<image v-if="web_url" :src="web_url+'/uniapp_image/xilu_profile_card.png'" mode="aspectFill"
								class="xilu_vip_nav_bg">
							</image>
							<view class="xilu_vip_nav_view plr30 flex-box">
								<view class="flex-grow-1">
									<view class="fs28 colf lh28">可提现金额（元）</view>
									<view class="fs30 mt20 colf lh50">¥<text class="fs50">0</text></view>
									<view class="fs28 colf lh28 mt40">全部金额（元）</view>
									<view class="fs30 colf lh34 mt15">¥<text class="fs34">0</text></view>
								</view>
								<view class="xilu_go">提现</view>
							</view>
						</view>
						<view class="xilu_box">
							<view class="fs36 fw500 colf lh36">其他功能</view>
							<view>
								<button class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_tool7.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>关于我们</view>
								</button>
								<button class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_tool8.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>帮助中心</view>
								</button>
							</view>
						</view>
					</view>
				</view>
			</template>

		</view>
		<u-authorize @onAuthCancel="onAuthCancel($event)" @onAuthConfirm="onAuthConfirm($event)"
			:popupStatus="auth_status" :isAuth="2"></u-authorize>
	</view>
</template>

<script>
	const app = getApp();
	const webConfig = require("@/util/config");
	export default {
		data() {
			return {
				config: {
					back: false,
					leftSlot: true,
					centerSlot: true,
					backgroundColor: [0, '#0F1011'],
					statusBarFontColor: ['#ffffff'],
					color: ['#ffffff']
				},
				web_url:'',
				login_status: false,
				auth_status: false,
				info: {
					expire: null
				},
				userInfo: null
			}
		},
		mounted() {
			
					
				this.$http({
					url:"/addons/xilufitness/shop/thali"
				}).then(res => {
					
				})
		},
		methods: {
			toBack() {
					this.$api.navigate('../mine/mine')
			},
			getVipStatusText(status) {
			  // 0=未开通|支付失败|未支付 1=未过期 2=已过期
			  switch(Number(status)) {
			    case 0: return '未开通';
			    case 1: return '使用中';
			    case 2: return '已过期';
			    default: return '--';
			  }
			},
			getVipStatusClass(status) {
			  switch(Number(status)) {
			    case 0: return 'status-unopen';
			    case 1: return 'status-active';
			    case 2: return 'status-expired';
			    default: return '';
			  }
			},
			formatDate(time) {
			  if (!time) return '--';
			  const d = new Date(Number(time) * 1000);
			  return `${d.getFullYear()}-${(d.getMonth()+1).toString().padStart(2,'0')}-${d.getDate().toString().padStart(2,'0')}`;
			},
			to_shop_member_card(recharge_id) {
					
					let _this = this;
					this.$api.navigate('../shop_member/shop_member?recharge_id=' + recharge_id,function(res) {
						res.eventChannel.emit('memberCardData', {
							userInfo: _this.info,
							rechargeInfo: _this.userInfo
						});
					})
				
			},
			toStudentJob(id) {
				this.$api.navigate('../students_job/students_job?id=' + id)
			},
			//获取详情
			getInfos() {
				let _this = this;
				this.$http({
					url: '/addons/xilufitness/shop/getShopInfo',
					method: 'get'
				}).then(res => {
					if (res.code == 1) {
						_this.info = res.data.info;
						_this.userInfo = res.data.userInfo;
					}
				}).catch(error => {
					console.log('coachInfoError', error);
				})
			},
			returnindex(url) {
				uni.reLaunch({
				    url: url
				});
			},
			//点击登录
			doLogin() {
				this.auth_status = true;
			},
			//授权取消
			onAuthCancel(e) {
				this.login_status = false;
				this.auth_status = false;
				this.$api.toast('取消授权，可能会使部分服务不能用，或页面信息不完整')
			},
			//授权成功
			onAuthConfirm(e) {
				this.login_status = true;
				this.auth_status = false;
				this.getInfos();
			},
			//页面跳转
			redirect_url(url) {
				let _this = this;
				this.$api.navigate(url, function(res) {
					res.eventChannel.emit('userData', {
						userInfo: _this.userInfo,
						coachInfo: _this.info
					});
					res.eventChannel.emit('coachData', {
						coachInfo: _this.info
					});
					res.eventChannel.on('coachWithdraw', function(params) {
						setTimeout(() => {
							console.log(1);
							_this.getInfos();
						}, 1000)
						
					});
				});
			}
		},
		onLoad() {
			this.web_url = webConfig.base_url || '';
			let token = this.$api.getCache('token');
			let _this = this;
			let shop = this.$api.getCache('is_shop') || 0;
			console.log(shop);
		
			if (token) {
				this.login_status = true;
				this.getInfos();
			}
			uni.$on('coachCheckOrder',function(params){
				_this.getInfos();
			});
		}
	}
</script>

<style lang="scss" scoped>
	.back {
		width: 40rpx;
		height:40rpx;
		z-index: 1000;
		font-size: 35rpx;
		color: #fff;
		position:absolute;
		top:118rpx;
		left:40rpx;
	}
	.back-img {
		width: 100%;
		height:100%;
	}
	.vip-status {
	  margin-top: 14rpx;
	  font-size: 28rpx;
	  font-weight: bold;
	  padding: 4rpx 22rpx;
	  border-radius: 18rpx;
	  display: inline-block;
	}
	.status-unopen {
	  background: #fff3e0;
	  color: #ff9800;
	}
	.status-active {
	  background: #e8f5e9;
	  color: #43a047;
	}
	.status-expired {
	  background: #ffebee;
	  color: #e53935;
	}
	.xilu {
		position: relative;

		&_mine_bg {
			width: 750rpx;
			height: 630rpx;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1;
		}

		&_head_img {
			width: 130rpx;
			height: 130rpx;
			border: 5rpx solid rgba(255, 255, 255, 0.3);
			border-radius: 50%;
		}

		&_sq {
			width: 2rpx;
			height: 43rpx;
			background: #A8A8A8;
		}

		&_vip_nav {
			width: 700rpx;
			height: 251rpx;
			position: relative;
			margin-bottom: 20rpx;
			&_bg {
				width: 700rpx;
				height: 251rpx;
				position: relative;
				border-radius: 20rpx;
			}

			&_view {
				width: 700rpx;
				height: 251rpx;
				position: absolute;
				top: 0;
				left: 0;
			}
		}

		&_go {
			width: 150rpx;
			height: 70rpx;
			line-height: 70rpx;
			text-align: center;
			font-size: 30rpx;
			font-weight: 400;
			color: #FFFFFF;
			background: #D7A35F;
			border-radius: 40rpx;
		}

		&_box {
			width: 700rpx;
			padding: 30rpx 25rpx 55rpx;
			background: #fff;
			border-radius: 20rpx;
			margin-top: 20rpx;
		}

		&_tool_item {
			margin-top: 50rpx;
			font-size: 26rpx;
			font-weight: 400;
			color: #B2B2B2;
			line-height: 26rpx;
			display: inline-block;
			vertical-align: top;
			margin-right: 78rpx;
			width: 104rpx;

			&_cover {
				width: 60rpx;
				height: 61rpx;
				display: block;
				margin-left: auto;
				margin-right: auto;
				margin-bottom: 20rpx;
			}

			&:nth-of-type(4n) {
				margin-right: 0;
			}
		}

		&_ad {
			width: 700rpx;
			height: 284rpx;
			display: block;
			margin-top: 20rpx;
		}
	}

	::v-deep.hx-navbar__content__main_center_txt {
		/* #ifdef MP */
		padding-left: 140rpx;
		/* #endif */
	}

	.ls10 {
		letter-spacing: 10rpx;
	}

	.tdu {
		text-decoration: underline;
	}

	.ico160 {
		width: 160rpx;
		height: 160rpx;
	}

	button {
		padding-left: 0;
		padding-right: 0;
		border-radius: 0;
	}
	
</style>